<?php
/* @var $this SnapshotController */
/* @var $model Project */

$this->breadcrumbs=array(
	Yii::t('monitor','Live List'),
);
?>

<script type="text/javascript">
	function initialize() {
	  	var map = new BMap.Map('baiduMap');
	  	var point = new BMap.Point(101.898517,30.116144);
	    map.centerAndZoom(point, 7);
//	  	map.enableScrollWheelZoom();

	    var bdary = new BMap.Boundary();
	    bdary.get("甘孜藏族自治州", function(rs){       //获取行政区域
	        map.clearOverlays();        //清除地图覆盖物       
	        var count = rs.boundaries.length; //行政区域的点有多少个
	        for(var i = 0; i < count; i++){
	            var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 2, strokeColor: "#ff0000"}); //建立多边形覆盖物
	            map.addOverlay(ply);  //添加覆盖物
	            map.setViewport(ply.getPath());    //调整视野         
	        } 
<?php 
	$markerIndex = 0;
	foreach($projects->search()->getData() as $eachData) {
	//	if(count($eachData->camerases) > 0 ) {
			echo 'var marker' . $markerIndex . ' = new BMap.Marker(new BMap.Point(' . $eachData->longitude . ', ' . $eachData->latitude . '));';
			echo 'map.addOverlay(marker' . $markerIndex . ');';
			echo 'var infoWindow' . $markerIndex . ' = new BMap.InfoWindow("' . Yii::t('monitor','Project Description') . ': ' . $eachData->description . '",
																						{width:200,title:"' . $eachData->name . '(<a href=\"' . $this->createUrl('live/view', array('cid'=>$eachData->county->id, 'pid'=>$eachData->id)) . '\">' . Yii::t('monitor','Click to see live.') . '</a>)"});';
			echo 'marker' . $markerIndex . '.addEventListener("click", function(){this.openInfoWindow(infoWindow' . $markerIndex . ');});';
			echo 'marker' . $markerIndex . '.addEventListener("mouseover", function(){changeTips("' . $eachData->name . '"); });';
			echo 'marker' . $markerIndex . '.addEventListener("mouseout", function(){changeTips("' . Yii::t('monitor','Please select project on the map.') . '"); });';
			$markerIndex++;
	//	}
		
	}
?>
             
	    });   
	}
	 
	function loadScript() {
	  var script = document.createElement("script");
	  script.src = "http://api.map.baidu.com/api?v=1.5&ak=5a90faa9eadcf6b86a4165ea8f218b47&callback=initialize";//此为v1.5版本的引用方式
	  // http://api.map.baidu.com/api?v=1.5&ak=您的密钥&callback=initialize"; //此为v1.4版本及以前版本的引用方式
	  document.body.appendChild(script);
	}
	 
	window.onload = loadScript;

	function changeTips(tipContent) {
		$("#projectTips").html(tipContent);
	}
</script>
<div class="row-fluid hidden-phone">
	<div class="span12">
		<div class="alert alert-info">
			<h1 class="text-center"> <?php echo Yii::t('monitor','Ganzi prefecture construction site live.'); ?> </h1>
		</div>
	</div>
</div>
<div class="row-fluid">
	<div class="span2">
<?php 
		//Display the county list
		$this->widget('bootstrap.widgets.TbGridView',array(
				'id'=>'county-grid-snapshot',
				'type'=>'striped bordered condensed',
				'template'=>"{items}",
				'dataProvider'=>$dataProvider,
				'selectionChanged'=>'function(id){redirectCountySnapshot();}',
				'columns'=>array(
						array(	
							'name'=>'name', 'header'=>Yii::t('monitor','Choose County'),
							'type'=>'raw',
							'value'=>'CHtml::link("$data->name","index.php?r=live/view&cid=".CHtml::encode($data->id))',
							'htmlOptions'=>array('style'=>'text-align:center;cursor:pointer;'), 'headerHtmlOptions'=>array('style'=>'text-align:center')),
				),
		));
?>
	</div>
	<div class="span10 hidden-phone">
		<div class="row-fluid">
			<div class="span12">
				<div id="baiduMap" style="width: 100%;min-height: 415px;overflow: hidden;margin:0;"></div>
			</div>
		</div>
		<div class="row-fluid">
			<div class="span12">
				<div id="projectTips" class="alert alert-info" style="text-align:center"><?php echo Yii::t('monitor','Please select project on the map.');?></div>
			</div>
		</div>
	</div>
</div>